home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech's Sprocket™ / SprocketGX / AppSpecific / GXToolWindow.cp < prev    next >
Encoding:
Text File  |  1994-10-17  |  14.1 KB  |  562 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        GXToolWindow.cp
  3.  
  4.     Contains:    A  palette window that will show info about the current shape
  5.                 
  6.     Written by: Jon Summers
  7.     
  8.     Copyright:    © 1994 by Jon Summers, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.  */
  13.  
  14. #include "GXToolWindow.h"
  15.  
  16. static long            gToolPage = 0;
  17. static long            gToolNumPages = 0;
  18. static gxShape    gToolPageShape = nil;
  19. static gxShape    gToolTestShape = nil;
  20.  
  21. gxShape    GetInspectShape(InspectShapeType theType);
  22. gxShape    GetInspectShape(InspectShapeType theType)
  23. {
  24.     switch (theType)
  25.     {
  26.         case ePageShape :        return gToolPageShape;
  27.         case eTestShape :        return gToolTestShape;
  28.     }
  29.     return nil;
  30. }
  31.  
  32. TGXToolWindow* TGXToolWindow::fgToolWindow = nil;
  33.  
  34. TGXToolWindow::TGXToolWindow()
  35.     : TToolWindow(1028)
  36. {
  37.     fgToolWindow = this;
  38. }
  39.  
  40. TGXToolWindow::~TGXToolWindow()
  41. {
  42.     fgToolWindow = nil;
  43. }
  44.  
  45. #define        kShapeTypeStrList            1000
  46. #define        kShapeAttributeStrList        1001
  47. #define        kShapePartStrList                1002
  48. #define        kShapeFillStrList                1003
  49.  
  50. #define    AppendChar(s, c)        s[++(*s)] = c
  51. #define    AppendComma(s)        AppendChar(s,',')
  52. #define    AppendSpace(s)            AppendChar(s,' ')
  53.  
  54. void    PrintListIndex(Str31  theStr, short theStrList, short theIndex);
  55. void    PrintListIndex(Str31  theStr, short theStrList, short theIndex)
  56. {
  57.     if (*theStr)
  58.     {
  59.         *theStr = 0;
  60.         AppendComma(theStr);
  61.         AppendSpace(theStr);
  62.         DrawString(theStr);
  63.     }
  64.     GetIndString(theStr, theStrList, theIndex);
  65.     DrawString(theStr);
  66. }
  67.  
  68. void    PrintShapeAttributes(gxShapeAttribute  theShapeAttribute);
  69. void    PrintShapeAttributes(gxShapeAttribute  theShapeAttribute)
  70. {
  71.     Str31        aStr;
  72.     *aStr = 0;
  73.     if (theShapeAttribute  == gxNoAttributes)
  74.         PrintListIndex(aStr, kShapeAttributeStrList, 1);
  75.     else
  76.     {
  77.         if (theShapeAttribute & gxDirectShape)
  78.             PrintListIndex(aStr, kShapeAttributeStrList, 2);
  79.         if (theShapeAttribute & gxRemoteShape)
  80.             PrintListIndex(aStr, kShapeAttributeStrList, 3);
  81.         if (theShapeAttribute & gxCachedShape)
  82.             PrintListIndex(aStr, kShapeAttributeStrList, 4);
  83.         if (theShapeAttribute & gxLockedShape)
  84.             PrintListIndex(aStr, kShapeAttributeStrList, 5);
  85.         if (theShapeAttribute & gxGroupShape)
  86.             PrintListIndex(aStr, kShapeAttributeStrList, 6);
  87.         if (theShapeAttribute & gxMapTransformShape)
  88.             PrintListIndex(aStr, kShapeAttributeStrList, 7);
  89.         if (theShapeAttribute & gxUniqueItemsShape)
  90.             PrintListIndex(aStr, kShapeAttributeStrList, 8);
  91.         if (theShapeAttribute & gxIgnorePlatformShape)
  92.             PrintListIndex(aStr, kShapeAttributeStrList, 9);
  93.         if (theShapeAttribute & gxNoMetricsGridShape)
  94.             PrintListIndex(aStr, kShapeAttributeStrList, 10);
  95.         if (theShapeAttribute & gxDiskShape)
  96.             PrintListIndex(aStr, kShapeAttributeStrList, 11);
  97.         if (theShapeAttribute & gxMemoryShape)
  98.             PrintListIndex(aStr, kShapeAttributeStrList, 12);
  99.     }
  100. }
  101.  
  102. void    PrintGxRect(gxRectangle* pRect);
  103. void    PrintGxRect(gxRectangle* pRect)
  104. {
  105.     Str31        aStr;
  106.     TextFace(bold);
  107.     *aStr = 0;
  108.     AppendSpace(aStr);
  109.     AppendChar(aStr, '[');
  110.     DrawString(aStr);
  111.     NumToString(pRect->left >> 16, aStr);
  112.     AppendComma(aStr);
  113.     DrawString(aStr);
  114.     NumToString(pRect->top >> 16, aStr);
  115.     AppendComma(aStr);
  116.     DrawString(aStr);
  117.     NumToString(pRect->right >> 16, aStr);
  118.     AppendComma(aStr);
  119.     DrawString(aStr);
  120.     NumToString(pRect->bottom >> 16, aStr);
  121.     AppendChar(aStr, ']');
  122.     DrawString(aStr);
  123.     TextFace(0);
  124. }
  125.  
  126. void    PrintGxPoint(gxPoint* pPoint);
  127. void    PrintGxPoint(gxPoint* pPoint)
  128. {
  129.     Str31        aStr;
  130.     TextFace(bold);
  131.     *aStr = 0;
  132.     AppendSpace(aStr);
  133.     AppendChar(aStr, '(');
  134.     DrawString(aStr);
  135.     NumToString(pPoint->x >> 16, aStr);
  136.     AppendComma(aStr);
  137.     DrawString(aStr);
  138.     NumToString(pPoint->y >> 16, aStr);
  139.     AppendChar(aStr, ')');
  140.     DrawString(aStr);
  141.     TextFace(0);
  142. }
  143.  
  144. void    PrintNumber(long  theNumber);
  145. void    PrintNumber(long  theNumber)
  146. {
  147.     Str31        aStr;
  148.     TextFace(bold);
  149.     DrawChar(' ');
  150.     NumToString(theNumber, aStr);
  151.     DrawString(aStr);
  152.     TextFace(0);
  153. }
  154.  
  155. void    PrintBit(long*    pLong, short  theIndex);
  156. void    PrintBit(long*    pLong, short  theIndex)
  157. {
  158.     long        aLong = pLong[theIndex/32];
  159.     short    aShift =  theIndex%32;
  160.     aShift = 32 - aShift;
  161.     if (aShift)
  162.         aLong >>= aShift;
  163.     DrawChar('0' +(aLong & 0x1));
  164. }
  165.  
  166. typedef    struct    // GXUniv
  167. {
  168.     union
  169.     {
  170.         gxRectangle         rect;
  171.         gxPoint             point;
  172.         gxLine                line;
  173.         gxCurve            curve;
  174.         gxBitmap            bitmap;
  175.     } u;
  176. } GXUniv;
  177. #define        kLineIncrement        12
  178. short    PrintTheShape(gxShape theShape, short theVert, short theHoriz);
  179. short    PrintTheShape(gxShape theShape, short theVert, short theHoriz)
  180. {
  181.     gxShapeType            aShapeType = GXGetShapeType(theShape);
  182.     gxShapeAttribute    aShapeAttribute = GXGetShapeAttributes(theShape);
  183.     gxShapeFill            aShapeFill = GXGetShapeFill(theShape);
  184.  
  185.     Str63    aStr;
  186.     short    aLineStart = theHoriz;
  187.     short    aLinePosn = theVert;
  188.     GXUniv         aUniv;
  189.     long            aSize;
  190.     long            aVector;
  191.     long            aContour;
  192.     
  193.     (void)GXGetShapeLocalBounds(theShape, &aUniv.u.rect);
  194.  
  195.     aLinePosn += kLineIncrement;
  196.     MoveTo(aLineStart, aLinePosn);
  197.     DrawString("\pType");
  198.     TextFace(bold);
  199.     DrawChar(' ');
  200.     *aStr = 0;
  201.     PrintListIndex(aStr, kShapeTypeStrList, aShapeType);
  202.     TextFace(0);
  203.     
  204.     aLinePosn += kLineIncrement;
  205.     MoveTo(aLineStart, aLinePosn);
  206.     DrawString("\pAttributes");
  207.     TextFace(bold);
  208.     DrawChar(' ');
  209.     PrintShapeAttributes(aShapeAttribute);
  210.     TextFace(0);
  211.     
  212.     aLinePosn += kLineIncrement;
  213.     MoveTo(aLineStart, aLinePosn);
  214.     DrawString("\pBounds");
  215.     PrintGxRect(&aUniv.u.rect);
  216.     
  217.     aLinePosn += kLineIncrement;
  218.     MoveTo(aLineStart, aLinePosn);
  219.     DrawString("\pFill");
  220.     TextFace(bold);
  221.     DrawChar(' ');
  222.     *aStr = 0;
  223.     PrintListIndex(aStr, kShapeFillStrList, aShapeFill+1);
  224.     TextFace(0);
  225.  
  226.     aLinePosn += kLineIncrement;
  227.     MoveTo(aLineStart, aLinePosn);
  228.     switch (aShapeType)
  229.     {
  230.         case gxEmptyType :        break;
  231.         case gxPointType :
  232.             DrawString("\pPoint");
  233.             (void)GXGetPoint(theShape, &aUniv.u.point);
  234.             PrintGxPoint(&aUniv.u.point);
  235. /***struct gxPoint {
  236.     Fixed                x;
  237.     Fixed                y;
  238. extern gxPoint *GXGetPoint(gxShape source, gxPoint *data)
  239. ***/
  240.             break;
  241.         case gxLineType :
  242.             DrawString("\pLine");
  243.             (void)GXGetLine(theShape, &aUniv.u.line);
  244.             TextFace(bold);
  245.             DrawChar(' ');
  246.             DrawString("\pfirst");
  247.             PrintGxPoint(&aUniv.u.line.first);
  248.             TextFace(bold);
  249.             DrawChar(' ');
  250.             DrawString("\plast");
  251.             PrintGxPoint(&aUniv.u.line.last);
  252. /***struct gxLine {
  253.     struct gxPoint                first;
  254.     struct gxPoint                last;
  255. extern gxLine *GXGetLine(gxShape source, gxLine *data)
  256. ***/
  257.             break;
  258.         case gxCurveType :
  259.             DrawString("\pCurve");
  260.             (void)GXGetCurve(theShape, &aUniv.u.curve);
  261.             TextFace(bold);
  262.             DrawChar(' ');
  263.             DrawString("\pfirst");
  264.             PrintGxPoint(&aUniv.u.curve.first);
  265.             TextFace(bold);
  266.             DrawChar(' ');
  267.             DrawString("\pcontrol");
  268.             PrintGxPoint(&aUniv.u.curve.control);
  269.             TextFace(bold);
  270.             DrawChar(' ');
  271.             DrawString("\plast");
  272.             PrintGxPoint(&aUniv.u.curve.last);
  273. /***        struct gxCurve {
  274.     struct gxPoint                first;
  275.     struct gxPoint                control;
  276.     struct gxPoint                last;
  277. extern gxCurve *GXGetCurve(gxShape source, gxCurve *data)
  278. ***/
  279.             break;
  280.         case gxRectangleType :
  281.             DrawString("\pRect");
  282.             (void)GXGetRectangle(theShape, &aUniv.u.rect);
  283.             PrintGxRect(&aUniv.u.rect);
  284. /***struct gxRectangle {
  285.     Fixed                        left;
  286.     Fixed                        top;
  287.     Fixed                        right;
  288.     Fixed                        bottom;
  289. extern gxRectangle *GXGetRectangle(gxShape source, gxRectangle *data)
  290. ***/
  291.             break;
  292.         case gxPolygonType :
  293.             DrawString("\pPolygon");
  294.             aSize = GXGetPolygons(theShape, nil);
  295. //            DrawString("\p Size ");
  296.             TextFace(bold);
  297. //            PrintNumber(aSize);
  298.             if (aSize)
  299.             {
  300.                 gxPolygons*        pPolygonsBlock = (gxPolygons*)NewPtr(aSize);
  301.                 if (pPolygonsBlock)
  302.                 {
  303.                     gxPolygon*    pPolygon = pPolygonsBlock->contour;
  304.                     
  305.                     (void)GXGetPolygons(theShape, pPolygonsBlock);
  306.                     TextFace(bold);
  307.                     DrawString("\p Contours ");
  308.                     PrintNumber(pPolygonsBlock->contours);
  309.                     aLineStart += kLineIncrement;
  310.                     for (aContour = 0; aContour < pPolygonsBlock->contours; ++aContour)
  311.                     {
  312.                         aLinePosn += kLineIncrement;
  313.                         MoveTo(aLineStart, aLinePosn);
  314.                         TextFace(0);
  315.                         DrawString("\pVectors ");
  316.                         TextFace(bold);
  317.                         PrintNumber(pPolygon->vectors);
  318.                         TextFace(bold);
  319.                         for (aVector = 0; aVector < pPolygon->vectors; ++aVector)
  320.                             PrintGxPoint(&pPolygon->vector[aVector]);
  321.                         pPolygon = (gxPolygon*)&pPolygon->vector[pPolygon->vectors];
  322.                     }
  323.                     DisposePtr((Ptr)pPolygonsBlock);
  324.                 }
  325.             }
  326. /***struct gxPolygon {
  327.     long                        vectors;
  328.     struct gxPoint        vector[1];
  329. struct gxPolygons {
  330.     long                        contours;
  331.     struct gxPolygon    contour[1];
  332. extern long GXGetPolygons(gxShape source, gxPolygons *data)
  333. extern gxPolygon *GetPolygon(gxShape source, long contour, gxPolygon *polygon);
  334. ***/
  335.             break;
  336.         case gxPathType :    
  337.             DrawString("\pPath");
  338.             aSize = GXGetPaths(theShape, nil);
  339.             DrawString("\p Size ");
  340.             TextFace(bold);
  341.             PrintNumber(aSize);
  342.             if (aSize)
  343.             {
  344.                 gxPaths*    pPathsBlock = (gxPaths*)NewPtr(aSize);
  345.                 if (pPathsBlock)
  346.                 {
  347.                     gxPath*    pPath = &pPathsBlock->contour[0];;
  348.                     (void) GXGetPaths(theShape, pPathsBlock);
  349.                     
  350.                     TextFace(bold);
  351.                     DrawString("\p Contours ");
  352.                     PrintNumber(pPathsBlock->contours);
  353.                     aLineStart += kLineIncrement;
  354.                     for (aContour = 0; aContour < pPathsBlock->contours; ++aContour)
  355.                     {
  356.                         long*            pControl = pPath->controlBits;
  357.                         gxPoint*        pVector;
  358.                         
  359.                         aSize = pPath->vectors+31;
  360.                         aSize /= 32;
  361.                         aSize *= sizeof(long);    // num of longs needed for control bits
  362.                         pVector = (gxPoint*)(((Ptr)pControl) + aSize);        // skip controlBits
  363.                         
  364.                         aLinePosn += kLineIncrement;
  365.                         MoveTo(aLineStart, aLinePosn);
  366.                         TextFace(0);
  367.                         DrawString("\pVectors ");
  368.                         TextFace(bold);
  369.                         PrintNumber(pPath->vectors);
  370.                         for (aVector = 0; aVector < pPath->vectors; ++aVector)
  371.                         {
  372.                             TextFace(bold);
  373.                             PrintGxPoint(&pVector[aVector]);
  374.                             TextFace(0);
  375.                             PrintBit(pControl, aVector);
  376.                             if (pPath->vectors > 5)
  377.                                 if (aVector == 4)
  378.                                 {
  379.                                     DrawChar('…');
  380.                                     aVector = pPath->vectors-2;    // force draw last
  381.                                 }
  382.                         }
  383.                         pPath = (gxPath*)&pVector[pPath->vectors];
  384.                     }
  385.                     DisposePtr((Ptr)pPathsBlock);
  386.                 }
  387.             }
  388. /***struct gxPath {
  389.     long                        vectors;
  390.     long                        controlBits[1];
  391.     struct gxPoint        vector[1];
  392. struct gxPaths {
  393.     long                        contours;
  394.     struct gxPath        contour[1];
  395. extern long GXGetPaths(gxShape source, gxPaths *data)
  396. extern gxPath *GetPath(gxShape source, long contour, gxPath *path);
  397. ***/
  398.             break;
  399.         case gxBitmapType :
  400.             DrawString("\pBitmap");
  401.             (void)GXGetBitmap(theShape, &aUniv.u.bitmap, nil);
  402.             aLinePosn += kLineIncrement;
  403.             MoveTo(aLineStart, aLinePosn);
  404.             TextFace(0);
  405.             DrawString("\p width ");
  406.             TextFace(bold);
  407.             PrintNumber(aUniv.u.bitmap.width);
  408.             TextFace(0);
  409.             DrawString("\p height ");
  410.             TextFace(bold);
  411.             PrintNumber(aUniv.u.bitmap.height);
  412.             TextFace(0);
  413.             DrawString("\p rowBytes ");
  414.             TextFace(bold);
  415.             PrintNumber(aUniv.u.bitmap.rowBytes);
  416.             TextFace(0);
  417.             DrawString("\p pixelSize ");
  418.             TextFace(bold);
  419.             PrintNumber(aUniv.u.bitmap.pixelSize);
  420.             TextFace(0);
  421. /***struct gxBitmap {
  422.     char                        *image;
  423.     long                        width;
  424.     long                        height;
  425.     long                        rowBytes;
  426.     long                        pixelSize;
  427.     gxColorSpace        space;
  428.     gxColorSet            set;
  429.     gxColorProfile        profile;
  430. extern gxBitmap *GXGetBitmap(gxShape source, gxBitmap *data, gxPoint *position)
  431. ***/
  432.             break;
  433.         case gxTextType :
  434.             DrawString("\pText");
  435.             aSize = GXGetText(theShape, nil, nil, nil);
  436.             TextFace(0);
  437.             DrawString("\p length ");
  438.             TextFace(bold);
  439.             PrintNumber(aSize);
  440.             TextFace(0);
  441.             if (aSize)
  442.             {
  443.                 if (aSize > 60)
  444.                     aSize = 60;
  445.                 (void)GXGetText(theShape, nil, &aStr[2], nil);
  446.                 aStr[1] = ' ';
  447.                 *aStr = aSize+1;
  448.                 aLineStart += kLineIncrement;
  449.                 aLinePosn += kLineIncrement;
  450.                 MoveTo(aLineStart, aLinePosn);
  451.                 TextFace(bold);
  452.                 DrawString(aStr);
  453.                 TextFace(0);
  454.             }
  455. /***
  456. extern long GXGetText(gxShape source, long *charCount, unsigned char text[], gxPoint *position)
  457. extern gxFont GXFindFont(gxFontStorageTag storage, gxFontStorageReference reference, gxFontAttribute *attributes)
  458. extern long GXFindFontName(gxFont fontID, gxFontName name, gxFontPlatform platform, gxFontScript script, gxFontLanguage language, unsigned char text[], long *index)
  459. extern gxFont GXGetShapeFont(gxShape source)
  460. extern Fixed GXGetShapeTextSize(gxShape source)
  461. extern fract GXGetShapeJustification(gxShape source)
  462. extern long GXGetShapeFace(gxShape source, gxTextFace *face)
  463. ***/
  464.             break;
  465.         case gxGlyphType :
  466.             DrawString("\pGlyph");
  467. /***
  468. extern long GXGetGlyphs(gxShape source, long *charCount, unsigned char text[], gxPoint positions[], long advance[], 
  469.                     gxPoint tangents[], long *runCount, short styleRuns[], gxStyle glyphStyles[])
  470. ***/
  471.             break;
  472.         case gxLayoutType :
  473.             DrawString("\pLayout");
  474. /***
  475. extern long GXGetLayout(gxShape layout, void *text, long *styleRunCount, short styleRunLengths[], gxStyle styles[], 
  476.                     long *levelRunCount, short levelRunLengths[], short levels[], gxLayoutOptions *layoutOptions, gxPoint *position);
  477. ***/
  478.         break;
  479.         case gxFullType :        break;
  480.         case gxPictureType :
  481. /***
  482. extern long GXGetPicture(gxShape source, gxShape shapes[], gxStyle styles[], gxInk inks[], gxTransform transforms[])
  483. ***/
  484.             break;
  485.     }
  486.     return aLinePosn;
  487. }
  488.  
  489. void TGXToolWindow::Draw(void)
  490. {
  491.     CSavePort  aSavePort(fWindow);
  492.     gxShape     aInspectShape = GetInspectShape(ePageShape);
  493.     short        aLineStart = 4;
  494.     short        aLinePosn = 2;
  495.     
  496.     TextFont(geneva);
  497.     TextSize(9);
  498.     
  499.     EraseRect(&fWindow->portRect);
  500.  
  501.     aLinePosn += kLineIncrement;
  502.     MoveTo(aLineStart, aLinePosn);
  503.     TextFace(bold);
  504.     DrawString("\pPage: ");
  505.     TextFace(0);
  506.  
  507.     if (aInspectShape)
  508.     {
  509.         TextFace(bold);
  510.         PrintNumber(gToolPage);
  511.         TextFace(0);
  512.         DrawString("\p of ");
  513.         TextFace(bold);
  514.         PrintNumber(gToolNumPages);
  515.         TextFace(0);
  516.  
  517.         aLinePosn = PrintTheShape(aInspectShape, aLinePosn, aLineStart+kLineIncrement);
  518.         
  519.         aInspectShape = GetInspectShape(eTestShape);
  520.         aLinePosn += kLineIncrement;
  521.         MoveTo(aLineStart, aLinePosn);
  522.         TextFace(bold);
  523.         DrawString("\pAt: ");
  524.         TextFace(0);
  525.         if (aInspectShape)
  526.             aLinePosn = PrintTheShape(aInspectShape, aLinePosn, aLineStart+kLineIncrement);
  527.         else
  528.             DrawString("\pnone");
  529.     }
  530.     else
  531.         DrawString("\pnone");
  532. }
  533.  
  534. void    SetInspectPage(long  thePageNum, long theNumOfPages)
  535. {
  536.     gToolPage = thePageNum;
  537.     gToolNumPages = theNumOfPages;
  538. }
  539.  
  540. void    SetInspectShape(InspectShapeType theType, gxShape  theShape)
  541. {
  542.     switch (theType)
  543.     {
  544.         case ePageShape :
  545.             if (gToolPageShape == theShape)
  546.                 return;
  547.             gToolPageShape = theShape;
  548.             gToolTestShape = nil;
  549.             break;
  550.         case eTestShape :
  551.             if (gToolTestShape == theShape)
  552.                 return;
  553.             gToolTestShape = theShape;
  554.             break;
  555.         default :
  556.             return;
  557.     }
  558.     if (TGXToolWindow::fgToolWindow)
  559.         TGXToolWindow::fgToolWindow->Draw();
  560. }
  561.  
  562.